package com.lujianfei.mqtt.ktx

import java.text.SimpleDateFormat
import java.util.*

/**
 * @Author: wn
 * @Date: 2024/4/23 14:05
 * @Description: 时间和日期工具类
 */
object DateUtil {
  const val MINUTE = (60 * 1000).toLong()

  const val HOUR = 60 * MINUTE

  const val DAY = 24 * HOUR

  const val WEEK = 7 * DAY

  const val MONTH = 4 * WEEK

  const val YEAR = 365 * DAY


  fun getDate(dateMillis: Long, pattern: String = "yyyy-MM-dd"): String {
    val sdf = SimpleDateFormat(pattern, Locale.getDefault())
    return sdf.format(Date(dateMillis))
  }

  /**
   * 获取当前时间
   */
   fun getDateAndTime(): String {
    val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
    return sdf.format(Date())
  }

   fun getDateAndHourMinuteTime(dateMillis: Long): String {
    val sdf = SimpleDateFormat("HH:mm", Locale.getDefault())
    return sdf.format(Date(dateMillis))
  }
}